<template>
	<view class="custom-level">
		<view class="member-upgrade-container">
			<view class="title">
				<text>会员升级</text>
				<!-- <navigator url="/pages/privilege" class="view-privilege">查看升级后会员特权 ></navigator> -->
			</view>
			<view class="level-progress">
				<view class="level-item" v-for="(level, index) in levels" :key="index">
					<view class="level-icon" v-if="index === currentLevelIndex">
						<image class="level-image" :src="level.icon" mode="aspectFit"></image>
					</view>
					<text :class="index <= currentLevelIndex? 'level-name-active' : 'level-name'">{{level.name}}</text>
				</view>
			</view>
			<view class="progress-bar">
				<view class="progress" :style="{width: progressWidth + '%'}"></view>
				<view class="progress-dots">
					<view class="progress-dot" v-for="(dot, dotIndex) in levels" :key="dotIndex"
						:class="{active: dotIndex <= currentLevelIndex}"></view>
				</view>
			</view>
			<view class="upgrade-info">
				<text>当前累计消费{{currentRecharge}}元还差{{targetRecharge - currentRecharge}}元即可升级</text>
			</view>
			<!-- <navigator url="/pages/upgradeStrategy" class="upgrade-strategy">升级攻略</navigator> -->
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				levels: [{
						name: '白银',
						icon: '/static/userLevel.png'
					},
					{
						name: '黄金',
						icon: '/static/userLevel.png'
					},
					{
						name: '‌白金',
						icon: '/static/userLevel.png'
					},
					{
						name: '钻石',
						icon: '/static/userLevel.png'
					},
				],
				currentLevelIndex: 0, // 当前会员等级索引，这里假设为小厨（0），实际根据业务获取
				currentRecharge: 0, // 当前累计充值金额，实际从后端获取
				targetRecharge: 1000, // 升级所需目标充值金额
				progressWidth: 0 // 进度条宽度百分比，初始为0，后续根据充值金额计算
			};
		},
		mounted() {
			// 这里假设根据充值金额计算进度条宽度，实际应根据业务逻辑处理
			if (this.currentRecharge > 0) {
				this.progressWidth = (this.currentRecharge / this.targetRecharge) * 100;
			}
		}
	};
</script>
<style lang="scss" scoped>
	.member-upgrade-container {
		border-radius: 10px;
		padding-top: 15rpx;
		padding-bottom: 15rpx;
		padding-left: 20rpx;
		padding-right: 20rpx;
		border-radius: 20rpx;
		box-shadow: 2rpx 2rpx 6rpx 1px rgba(154, 154, 154, 0.37);
	}

	.title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 15px;
	}

	.title text {
		font-size: 20px;
		font-weight: bold;
	}

	.view-privilege {
		color: #999;
		text-decoration: none;
	}

	.level-progress {
		display: flex;
		justify-content: space-around;
	}

	.level-item {
		display: inline-block;
		text-align: center;
		margin-right: 15px;
	}

	.level-icon {
		float: left;
	}

	.level-name-active {
		color: #333;
		font-weight: bold;
	}

	.level-name {
		color: #999;
	}

	.progress-bar {
		top: -3px;
		background-color: #e6e6e6;
		border-radius: 5px;
		margin-bottom: 15rpx;
	}

	.progress {
		height: 100%;
		background-color: #f7ba5b;
		border-radius: 5px;
	}

	.progress-dots {
		top: -5px;
		left: 0;
		right: 0;
		display: flex;
		justify-content: space-around;
	}

	.progress-dot {
		width: 10px;
		height: 10px;
		border-radius: 50%;
		background-color: #DCDCDC;
	}

	.active {
		background-color: #f7ba5b;
	}

	.upgrade-info {
		font-size: 16px;
		margin-bottom: 15px;
	}

	.upgrade-strategy {
		background-color: #333;
		color: #fff;
		padding: 10px 20px;
		border-radius: 20px;
		text-decoration: none;
		display: inline-block;
	}

	.level-image {
		width: 20px;
		height: 20px;
		margin-bottom: 5px;
	}

	.custom-level {
		padding: 20rpx;
	}
</style>